Skip to content

feat: support custom per-instance OpenTelemetry TracerProvider#517

Merged
rbarbadillo merged 1 commit intomainfrom
rbarbadillo/obs-1582-mistral-python-sdk-supporting-custom-otel-provider
May 7, 2026
Merged

feat: support custom per-instance OpenTelemetry TracerProvider#517
rbarbadillo merged 1 commit intomainfrom
rbarbadillo/obs-1582-mistral-python-sdk-supporting-custom-otel-provider

Conversation

@rbarbadillo
Copy link
Copy Markdown
Contributor

@rbarbadillo rbarbadillo commented May 6, 2026

Summary

Add a hook-based helper for per-instance OpenTelemetry tracing in the Python SDK.

set_tracer_provider(client, provider) attaches a custom TracerProvider to a specific Mistral client instance, so spans emitted by that client go through the provided OTEL pipeline while other SDK instances continue using the global provider.

Changes

  • add mistralai.extra.observability.set_tracer_provider
  • teach TracingHook to use a configured per-instance provider
  • update get_or_create_otel_tracer() to accept an optional provider
  • preserve the current global-provider fallback
  • add tests for custom provider and fallback behavior

Usage

from opentelemetry.sdk.trace import TracerProvider
from mistralai.client import Mistral
from mistralai.extra.observability import set_tracer_provider

client = Mistral(api_key="...")
set_tracer_provider(client, TracerProvider())

@rbarbadillo rbarbadillo self-assigned this May 6, 2026
Copy link
Copy Markdown
Contributor

@louis-sanna-dev louis-sanna-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diff is modying generated code, plz use hooks for those use-case. (See Agents.md for more details)

@rbarbadillo rbarbadillo marked this pull request as draft May 6, 2026 18:08
@louis-sanna-dev
Copy link
Copy Markdown
Contributor

louis-sanna-dev commented May 6, 2026

Actually I see hooks are NOT* documented in Agents.md.

here is the doc https://www.speakeasy.com/docs/sdks/customize/code/sdk-hooks , it's already used a lot in this repo.

@rbarbadillo rbarbadillo force-pushed the rbarbadillo/obs-1582-mistral-python-sdk-supporting-custom-otel-provider branch from 0cfb147 to fde0f9f Compare May 6, 2026 18:59
…r_provider

Add a set_tracer_provider(client, provider) helper that attaches a custom
TracerProvider to a specific Mistral client instance. Spans produced by
that client are emitted through the custom provider; other instances
continue using the global provider.

Usage:
    from mistralai.extra.observability import set_tracer_provider
    set_tracer_provider(client, my_provider)

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@rbarbadillo rbarbadillo force-pushed the rbarbadillo/obs-1582-mistral-python-sdk-supporting-custom-otel-provider branch from fde0f9f to adeff87 Compare May 6, 2026 19:11
@rbarbadillo rbarbadillo marked this pull request as ready for review May 6, 2026 19:46
@rbarbadillo rbarbadillo merged commit 99fb677 into main May 7, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants